<template>
  <div class="app-page">
    <div class="app-main-container">
      <a-button type="primary" @click="addRowHandle">
        添加按钮
      </a-button>
      <a-button type="link" size="small" @click="editRowHandle(1)">
        编辑
      </a-button>
    </div>
    <ruleFormDialog
      v-if="dialogVisible"
      :visible.sync="dialogVisible"
      :detail-data="detailData"
      :is-edit="isEdit"
      @success="successHandle"
    />
  </div>
</template>

<script>
import { getData } from '@/mock/index'
import ruleFormDialog from './children/ruleFormDialog'
export default {
  name: 'DialogAddEdit',
  components: {
    ruleFormDialog
  },
  data() {
    return {
      isEdit: false,
      // 详情数据
      detailData: {},
      dialogVisible: false
    }
  },
  methods: {
    // 成功
    successHandle() {},
    // 增加
    addRowHandle() {
      this.dialogVisible = true
      this.isEdit = false
      this.detailData = {}
    },
    // 编辑
    async editRowHandle(id) {
      const res = await getData({ id }, {})
      if (res.code === 1) {
        console.log('编辑')
        this.dialogVisible = true
        this.isEdit = true
        this.detailData = res.data
      } else {
        this.$notification.error({
          message: '获取编辑信息失败!'
        })
      }
    }
  }
}
</script>

<style lang="less" scoped></style>
